<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-10-24
 * Time: 上午 11:10
 */

namespace App\Lib\DingDingNotice;


class Liver extends BaseNotice
{
    /*
     * $PhoNum 接受方联系方式
     * $smsNumber 发送方联系方式
     * $smsContent 短信内容
     * $smsDate 短信发送时间
     * $token 钉钉token
     * $atMobiles 需要at的人
     * $isAtall 是否at所有人
     * */
    public function __construct($type,$startTime,$endTime,$liverContent,$token,$atMobiles = [],$isAtall = false)
    {
        $last           =   'http://dd.youdnr.com/api/order/liver_notice?type=2';
        $lastAgain      =   "http://dd.youdnr.com/api/order/liver_notice?type=$type&sign=1";
        $today          =   'http://dd.youdnr.com/api/order/liver_notice?type=1';
        $collect        =   "http://dd.youdnr.com/api/order/fxg";

        $str = "\n\n > 开始时间 : $startTime";
        $str .= "\n\n > 结束时间 : $endTime";
        foreach ($liverContent as $k=>$v){

            $str .= "\n\n >主播 : ".$v['name']."(".$v['customer_total_count'].' / '.$v['customer_new_total_count'].")";
            $info = $v['infos'];
            foreach ($info as $kk=>$vv){
                $back_cost_total_price = (float)$vv['back_cost_total_price'];//成本
                $back_shop_total_price = (float)$vv['back_shop_total_price'];//总售价
                $profit = $back_shop_total_price-$back_cost_total_price;
                $text   =   '暂无';
                if($vv['back_order_count']){

                    $profit_rate = round($profit/$back_shop_total_price*100,2);
                    $text = $back_shop_total_price.' / '. $vv['back_order_count'].' / '.$vv['back_cost_total_price'].' / '.$profit.' / '.$profit_rate."%";

                }

                $str .= "\n\n >".$vv['order_status_text']."：".$vv['shop_total_price'];
                $str .= "\n\n > ($text)";
                $str .= "\n\n >优惠券金额：".$vv['coupon_total_amount'];
            }
            $str .= "\n\n >=======================";
        }

        $str .=  "\n\n > [前一天]($lastAgain) 
        \n\n > [昨天]($last) 
        \n\n > [今天]($today)
        \n\n > [采集]($collect)
        \n\n > 发送时间: ".date("Y-m-d H:i:s");

        $this->template = [
            "title"=>'主播业绩通知',
            'text'=>"#### 主播业绩通知
            \n\n > $str"
        ];

        $this->token = $token;
        $this->atMobiles = $atMobiles;
        $this->isAtall = $isAtall;
    }

}